//
//  RVNewddressController.swift
//  AirTravel
//
//  Created by apple on 2021/11/29.
//

import UIKit

class RVNewddressController: CommonVC {

    
    @IBOutlet weak var peopleTF: UITextField!
    
    @IBOutlet weak var telTF: UITextField!
    
    @IBOutlet weak var regionTF: UITextField!
    
    @IBOutlet weak var detailTF: UITextField!
    
    @IBOutlet weak var dftSwitch: UISwitch!
    
    @IBOutlet weak var saveBtn: UIButton!
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        head.title.text = "新增地址"
        regionTF.delegate = self
        saveBtn.setBtnGradient()
    }


    @IBAction func clickSaveBtn(_ sender: UIButton) {
        if peopleTF.text?.count == 0 {
            YProgressHUD.showToast("请输入收货人")
            return
        }
        
        if telTF.text?.count == 0 {
            YProgressHUD.showToast("请输入手机号")
            return
        }
        
        if regionTF.text?.count == 0 {
            YProgressHUD.showToast("请选择地区")
            return
        }
        
        if detailTF.text?.count == 0 {
            YProgressHUD.showToast("请输入详细地址")
            return
        }
        
        
    }
    
}


extension RVNewddressController: UITextFieldDelegate{
    
    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        self.view.endEditing(true)
        showRegionPicker()
        return false
    }
    
    func showRegionPicker() {
        BRAddressPickerView.showAddressPicker(withSelectIndexs: nil) {[weak self] province, city, area in
            
            let p = province?.name ?? ""
            let c = city?.name ?? ""
            let a = area?.name ?? ""
            
            let str = p + c + a
            self?.regionTF.text = str
            
        }
    }
}
